﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.Core.Exceptions;
using Enterprise.Framework.DomainModel.Repositories;

namespace Resto.CostControl.Core.Domain.Query.DishOrderModule
{
    internal class DishOrderDQO : IDomainQueryObject
    {
        public DishOrder GetDishOrder(string id)
        {
            DishOrder order = GetDishOrderOrDefault(id);

            if (order == null)
                throw new BusinessException("指定Id的菜肴不存在");

            return order;
        }

        public DishOrder GetDishOrderOrDefault(string id)
        {
            IEntityRepository<DishOrder> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<DishOrder>();
            DishOrder order = repository.Objects.Where(p => p.ID == id).FirstOrDefault();

            return order;
        }
    }
}
